//
//  ViewController.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/3/22.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import MJRefresh


class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    
    @IBOutlet weak var leftTableView: UITableView!
    let header = MJRefreshNormalHeader()
    let footer = MJRefreshAutoNormalFooter()
    
    
    // MARK: - DataSource\ Delegate
    // 区
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    // 行
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    // 高
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
        cell.textLabel!.text = "重新看看"
        cell.imageView?.image = UIImage.init(named: "home-icon2.png")
        return cell
    }
    
    //MARK: - setRefresh
    var _index = 0 // 模拟数据
    
    func setTableViewRefresh()  {
        header.setRefreshingTarget(self, refreshingAction: #selector(self.headerRefresh))
        header.setTitle("标题", for: MJRefreshState.idle)
        header.setTitle("正在刷新中..", for: MJRefreshState.refreshing)
        header.setTitle("没有数据了", for: MJRefreshState.noMoreData)
        
        self.leftTableView.mj_header = header
        footer.setRefreshingTarget(self, refreshingAction: #selector(self.footerRefresh))
        self.leftTableView.mj_footer = footer
    }
    @objc func headerRefresh () {
        self.leftTableView.mj_header.endRefreshing()
    }
    @objc func footerRefresh() {
        self.leftTableView.mj_footer.endRefreshing()
        _index += 1
        if _index > 2 {
            footer.endRefreshingWithNoMoreData()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setTableViewRefresh()

        
//        let url = "https://health.zhzjzdh.com/user/debug3"
//        let dic:NSDictionary? = [] as! Any
//        NetRequestTool.shareInstance.netRequest(metString: "POST", urlString: url, paramsAny: nil) { (response:[String: AnyObject]?, err: NSError?) in
//            debugPrint("------\(String(describing: response))")
//        }
        
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

